package com.develop.skwen.electricgomall.home;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.widget.RelativeLayout;

import com.develop.skwen.basemodule.util.StatusBarUtil;
import com.develop.skwen.basemodule.view.BaseView;
import com.develop.skwen.electricgomall.R;

/**
 * Created by skwen
 * on 18-5-29
 */

public class HomeView extends BaseView<HomeContract.HomePresenter> implements HomeContract.HomeVu {


    private SwipeRefreshLayout mRefreshLayout;

    private RecyclerView mRecyclerView;

    private RelativeLayout mToolBarLayout;


    @Override
    protected int getLayoutRes() {
        return R.layout.home_layout;
    }

    @Override
    protected void initViews() {
        mToolBarLayout = findViewById(R.id.toolbar_layout);
        mRefreshLayout = findViewById(R.id.home_refresh);
        mRecyclerView = findViewById(R.id.home_list);
        setMargins(mToolBarLayout,0,StatusBarUtil.getStatusBarHeight(getActivity()),0,0);
        addListener();
    }

    private void addListener() {
        mRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getPresenter().onRefresh();
            }
        });
    }

    @Override
    public void setAdapter(RecyclerView.Adapter adapter) {
        mRecyclerView.setLayoutManager(getPresenter().getLayoutManager());
        mRecyclerView.setAdapter(adapter);
    }

    @Override
    public void stopRefresh() {
        mRefreshLayout.setRefreshing(false);
    }
}
